﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using DataLib.Common;
using DataLib.Accounts.Bus;

namespace Ewts.BaseData
{
    public partial class PlateNumberModify : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dropCity.DataSource = new DataLib.BLL.City().GetList("flag1='02'").Tables[0];
                dropCity.DataTextField = "cityname";
                dropCity.DataValueField = "cityname";
                dropCity.DataBind();


                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(id);
                }
            }
        }

        private void ShowInfo(int id)
        {
            DataLib.BLL.PlateNumber bll = new DataLib.BLL.PlateNumber();
            DataLib.Model.PlateNumber model = bll.GetModel(id);
           // this.lblid.Text = model.id.ToString();
            this.txttransportIid.Text =model.transportIid.ToString();
            dropCity.SelectedValue = model.city;
            this.txtvehicletype.Text = model.vehicletype;
            this.txtplateno.Text = model.plateno;
            this.txtmaxton.Text = model.maxton.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";


            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int id = (Convert.ToInt32(Request.Params["id"]));
            int transportIid = int.Parse(this.txttransportIid.Text);
            string city = dropCity.SelectedItem.Text;
            string vehicletype = this.txtvehicletype.Text;
            string plateno = this.txtplateno.Text;
            decimal maxton = decimal.Parse(this.txtmaxton.Text);


            DataLib.Model.PlateNumber model = new DataLib.Model.PlateNumber();
            model.id = id;
            model.transportIid = transportIid;
            model.city = city;
            model.vehicletype = vehicletype;
            model.plateno = plateno;
            model.maxton = maxton;

            DataLib.BLL.PlateNumber bll = new DataLib.BLL.PlateNumber();
            bll.Update(model);
            DataLib.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "PlateNumberList.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("PlateNumberList.aspx");
        }
    }
}